<!--编辑或添加商户信息-->
<div id='Store_Main_SubArea' >
	<div style='margin:10px auto;display:flex'>
		<div style='width:100px;text-align:right'>商户名称：</div>
		<div style='flex:1'><input id='StoreEdit_Name' style='width:90%' /></div>
	</div>
	<div style='margin:10px auto;display:flex'>
		<div style='width:100px;;text-align:right'>联系电话：</div>
		<div style='flex:1'><input id='StoreEdit_Phone' /></div>
	</div>
	<div style='margin:10px auto;display:flex'>
		<div style='width:100px;text-align:right'>Q Q：</div>
		<div style='flex:1'><input id='StoreEdit_Qq' /></div>
	</div>
	<div style='margin:10px auto;display:flex'>
		<div style='width:100px;;text-align:right'>微信：</div>
		<div style='flex:1'><input id='StoreEdit_Wx' /></div>
	</div>
	<div style='margin:10px auto;display:flex'>
		<div style='width:100px;;text-align:right'>商户地址：</div>
		<div style='flex:1'><input id='StoreEdit_Addr' style='width:90%' /></div>
	</div>
	<div style='margin:10px auto;display:flex'>
		<div style='width:100px;;text-align:right'>商户描述：</div>
		<div style='flex:1'><textarea id="StoreEdit_Info" style='width:90%;height:150px;resize:none' ></textarea></div>
	</div>


	<div style='margin:10px auto;display:flex'>
		<div style='width:100px;text-align:right'>店铺封面：</div>
		<div style='flex:1'>
			<input type="file" id='StoreEdit_File'  />
		</div>
	</div>

	<div style='margin:10px auto;display:flex'>
		<div style='width:100px;;text-align:right'>验证码　：</div>
		<div style='flex:1;display:flex;height:30px'>
			<div style='width:80px'>
				<input id='StoreEdit_Code' style='height:100%;width:80px' />
			</div>
			<div style='flex:1;padding-left:10px;'>
				<img src="interface.php?type=code" id='StoreEdit_CodeImg' style='height:100%;width:90px' alt="点击" onclick='ChangeCode(this)'>
			</div>
		</div>
	</div>
	

	<div style='text-align:center;margin:20px auto'>
		<button id='StoreEdit_SubBtn'>提交</button>
		<button id='StoreEdit_BackBtn'>返回</button>
	</div>
</div>



<script>

	var StoreEdit_AddFile;	//添加时封面图的临时变量
	var EditFile;	//编辑时封面图的临时变量

	//返回按钮
	$('#StoreEdit_BackBtn').click(function(){
		$('#StoreMain_Area').show();
		$('#StoreMain_StoreEdit').hide();
	});


	//添加或编辑商户信息提交
	$('#StoreEdit_SubBtn').click(function(){
	//	C(StoreInfo);
		var StoreInfo2 = StoreInfo;  //设置一个临时变量缓存修改后的数据，提交成功后，再赋值给原变量
		var StoreEdit_Name = ChangeChar($('#StoreEdit_Name').val().trim());
		Field_Check(/^.{3,20}$/,StoreEdit_Name,'js商户名长度为3-20个字符!');

		var StoreEdit_Phone = ChangeChar($('#StoreEdit_Phone').val().trim());
		Field_Check(/^[1-9][0-9]{6,11}$/,StoreEdit_Phone,'js电话格式不正确!');
	
		var StoreEdit_Qq = ChangeChar($('#StoreEdit_Qq').val().trim());
		Field_Check(/^[1-9][0-9]{4,11}$|^$/,StoreEdit_Qq,'jsQQ号不正确!');

		var StoreEdit_Wx = ChangeChar($('#StoreEdit_Wx').val().trim());
		Field_Check(/^[a-zA-z0-9_-]{3,30}$|^$/,StoreEdit_Wx,'js微信号格式不正确!');

		var StoreEdit_Addr = ChangeChar($('#StoreEdit_Addr').val().trim());
		Field_Check(/^.{1,50}$|^$/,StoreEdit_Addr,'js地址长度不超过50个字符!');

		var StoreEdit_Info = ChangeChar($('#StoreEdit_Info').val().trim());
		Field_Check(/^.{1,300}$/,StoreEdit_Info,'js商户描述不得为空且不得超过300字符!');

		var StoreEdit_Code = ChangeChar($('#StoreEdit_Code').val().trim());
		Field_Check(/.+/,StoreEdit_Code,'js验证码不得为空!');
	
		//Notice('处理中......');
		var formData = new FormData();
		if(StoreEdit_AddFile){
			formData.append('banner',StoreEdit_AddFile); //添加文件
		}
		formData.append('name',StoreEdit_Name); 

		formData.append('phone',StoreEdit_Phone); 
		
		if(StoreEdit_Qq){
			formData.append('qq',StoreEdit_Qq); 
		}
		if(StoreEdit_Wx){
			formData.append('wx',StoreEdit_Wx); 
		}
		if(StoreEdit_Addr){
			formData.append('addr',StoreEdit_Addr); 
		}
		
		formData.append('info',StoreEdit_Info); 
		
		formData.append('code',StoreEdit_Code); 


		var type = 'StoreInfoAddOrEdit';
		formData.append('type',type); 
		formData.append('openid',StoreInfo.openid); 
		formData.append('city_val',StoreInfo.city_code+","+StoreInfo.db_host+","+StoreInfo.db_name); 


		Ajax_FormData2(formData,after_url,function(res){
			C(res);
			if(/^{"id":.*$/.test(res)){
				A('操作成功！');
				sessionStorage.StoreInfo = res;
				StoreInfo = JSON.parse(res);
				StoreMain();
				return;
			}

			switch(res){
				case 'ok':
					A('操作成功！');
					break;
				case 'err1':
					A('验证码不正确!');
				break;
				case 'err6':
					A('商户已封禁!');
				break;
				case 'err7':
					A('数据没有任何改动!');
				break;
				default:
					A('系统异常，请稍再试!');
				break;
			}
			$('#StoreEdit_CodeImg').trigger('click');
		});
	});











	//选择图片并验证保存到变量中
	SelectOrViewImg('StoreEdit_File','StoreMain_Banner',function(file){
		if(file != 'err'){
			StoreEdit_AddFile = file;
		}else{
			A('文件类型不正确或大小超限!');
		}
	});	//限制大小500k


	StoreEdit_PasrseStoreInfo(sessionStorage.StoreInfo);	//解析并显示商户信息


	//解析并显示商户信息
	function StoreEdit_PasrseStoreInfo(res){
		if(!/^{"id":.*$/.test(res)){
			return;
		}
		var info = JSON.parse(res);
		$('#StoreEdit_Name').val(ChangeChar(info.name,1));
		$('#StoreEdit_Phone').val(info.phone);
		$('#StoreEdit_Qq').val(info.qq);
		$('#StoreEdit_Wx').val(info.wx);
		$('#StoreEdit_Addr').val(ChangeChar(info.addr,1));
		$('#StoreEdit_Info').val(ChangeChar(info.info,1));
	}
</script>